home *** CD-ROM | disk | FTP | other *** search
- unit Cppclu;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, ExtCtrls;
-
- type
-
- { Mirror of the real C++ class - note the additional method attributes }
- TDLLClass = class
- procedure SetValue(Info : integer); virtual; abstract;
- function GetValue : integer; virtual; abstract;
- procedure SetEvent(func : TNotifyEvent); virtual; abstract;
- public
- procedure ShowTheValue; virtual; abstract;
- procedure DoEvent; virtual; abstract;
-
- property AnEvent : TNotifyEvent write SetEvent;
- property DLLValue: integer read GetValue write SetValue;
- end;
-
- TForm1 = class(TForm)
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- Button4: TButton;
- Button5: TButton;
- Button6: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure Button4Click(Sender: TObject);
- procedure Button5Click(Sender: TObject);
- procedure Button6Click(Sender: TObject);
-
- private
- procedure DisEnableAllButtons;
-
- public
- procedure bProc(Sender: TObject); export;
- procedure cProc(Sender: TObject); export;
- end;
-
-
- var
- Form1: TForm1;
- { Instance of C++ class created in C++ DLL }
- ACppClass : TDLLClass;
-
-
- implementation
-
- {$R *.DFM}
-
- { Make a C++ class }
- function ConstructClass : TDllClass; far; external 'CPPDLL';
- procedure DestructClass(DLLClass :TDllClass); far; external 'CPPDLL';
-
- procedure TForm1.bProc(Sender: TObject);
- begin
- Color := clRed;
- Caption := 'a GeneralEvent';
- end;
-
- procedure TForm1.cProc(Sender: TObject);
- begin
- Color := clGreen;
- Caption := 'another GeneralEvent';
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- ACppClass := ConstructClass;
- if ACppClass <> nil then
- DisEnableAllButtons;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- with ACppClass do
- begin
- { Call methods of C++ object }
- ShowMessage(Format('C++ class Before: %d', [DLLValue]));
- DLLValue := DLLValue + 10;
- ShowMessage(Format('C++ class After: %d', [DLLValue]));
- ShowThevalue;
- end;
- end;
-
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- ACppClass.AnEvent := bProc;
- end;
-
- procedure TForm1.Button4Click(Sender: TObject);
- begin
- ACppClass.AnEvent := cProc;
- end;
-
- procedure TForm1.Button5Click(Sender: TObject);
- begin
- ACppClass.DoEvent;
- end;
-
- procedure TForm1.DisEnableAllButtons;
- var
- i : integer;
- begin
- {Flip all buttons to opposite state}
- for i := 0 to ControlCount-1 do
- if Controls[i] is TButton then
- with TButton(Controls[i]) do
- Enabled := not Enabled;
- end;
-
- procedure TForm1.Button6Click(Sender: TObject);
-
- begin
- DestructClass(ACppClass);
- ACppClass := nil;
- if ACppClass = nil then
- DisEnableAllButtons;
-
- end;
-
- end.
-